package com.aegean.MonitorExamSYS.conduction.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.conduction.business.ConductionBusiness;
import com.aegean.MonitorExaxSYS.model.ConductionValue;
import com.aegean.MonitorExaxSYS.model.ExamPosition;
import com.opensymphony.xwork2.ActionSupport;

@Controller("ShowExamPosition")
@Scope("prototype")
public class ShowExamPosition extends ActionSupport {
	@Resource
	ConductionBusiness business;
	private String query;
	private int start;
	private int limit;
	private int total;
	private List<ExamPosition> examPositions = new ArrayList<ExamPosition>();

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	private ConductionValue conduction;

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public List<ExamPosition> getExamPositions() {
		return examPositions;
	}

	public void setExamPositions(List<ExamPosition> examPositions) {
		this.examPositions = examPositions;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		HttpSession session = ServletActionContext.getRequest().getSession();
		conduction = (ConductionValue) session.getAttribute("ConductionLogin");
		if (query == null||query.equals("") || query.length() == 0) {
			total = business.examPositionCount(conduction.getConduction_Id());
			examPositions = business.ShowExamPositions(start, limit,
					conduction.getConduction_Id());
		} else {
			total = business.examPositionCountQuery(query.trim(),conduction.getConduction_Id());
			examPositions = business.ShowExamPositionsQuery(query.trim(),start, limit,
					conduction.getConduction_Id());
		}
		return SUCCESS;
	}

}
